package com.ysjweb.dish.Service;

import com.ysjweb.dish.Mapper.UserMapper;
import com.ysjweb.dish.Service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class userService implements UserServiceImpl {
    @Autowired
    UserMapper userMapper;

    @Override
    public String GetFavoriteById(Integer id) {
        return userMapper.GetFavoriteById(id);
    }

    @Override
    public void UpdateFavoriteById(Integer id, String favorite) {
        userMapper.UpdateFavoriteById(id, favorite);
    }

    @Override
    public boolean AddUser(String username, String password) {
        if (username == null || password == null) {
            return false;
        }
        if(userMapper.GetUserIdByUsername(username) == null) {
            userMapper.AddUser(username, password);
            return true;
        }
        return false;
    }

    @Override
    public boolean ExistUsername(String username, String password) {
        return userMapper.GetUserId(username, password) != null;
    }

    @Override
    public Integer GetUserId(String username, String password) {
        return userMapper.GetUserId(username, password);
    }
}
